package com.avcdata.aoscustommade.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.view.View;

import com.avcdata.aoscustommade.utils.ToastUtils;

/**
 * 全局网络广播
 */
public class MyReceiver extends BroadcastReceiver {

    public View view;

    public MyReceiver(){
        super();
    }


    public MyReceiver(View view){
        super();
        this.view = view;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo  mobNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo  wifiNetInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
            ToastUtils.showShort(context, "请连接网络");
            view.setVisibility(View.GONE);
            //改变背景或者 处理网络的全局变量
        }else {
            //改变背景或者 处理网络的全局变量
        }
    }





}
